package com.ecom.common.service;

import com.ecom.common.dao.ProductDao;
import com.ecom.common.model.Category;
import com.ecom.common.model.Product;
import com.ecom.common.model.SubCategory;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jimmy on 7/18/14.
 */
@Service
public class ProductService {

    private static final Logger logger = Logger.getLogger(ProductService.class);

    @Autowired
    ProductDao productDao;

    public int checkDatabase() {

        int value = this.productDao.checkDatabase();

        logger.debug(" checkdatabase: " + String.valueOf(value));

        return value;
    }

    public List<Category> getCategories() {

        return productDao.getCategoryList();

    }

    public List<SubCategory> getSubCategories(Category category) {

        return productDao.getSubCategoryList(category);

    }

    public List<Product> getProductFromCategory(String productType, Category category) {

        List<Product> products = new ArrayList<Product>();

        if (productType.equals("book")) {
            products = productDao.getBookListFromCategory(category);
        } else {
            products = productDao.getMovieListFromCategory(category);
        }

        return products;
    }

    public List<Product> getProductFromSubCategory(String productType, SubCategory subCategory) {

        List<Product> products = new ArrayList<Product>();

        if (productType.equals("book")) {
            products = productDao.getBookListFromSubCategory(subCategory);
        } else {
            products = productDao.getMovieListFromSubCategory(subCategory);
        }

        return products;
    }
}
